app.controller('GetDevicesCtrl',function ($scope,$http,$localStorage,$location,$window,$state) {
	$scope.namedata = $localStorage.cur_user.uname;
	$scope.getdevicelist = function(pa){
      $scope.currentPage = 1;//初始当前页
      $scope.maxSize = 3;//最多显示3页其他的用···代替

      $http.post(
            $scope.app.backendurl+"tbl-equipment/view-all",
            {    
                'page': $scope.currentPage,  
                'product_id':$state.params.pid,   
                'token':$localStorage.token                  

            }
        ).success(function (data) {
         //console.log(data);
          if(data.code==0&&data.msg=='获取设备详细数据成功'){
            $scope.aaData = data.data.list;
            $scope.totalItems = data.data.page.totalCount;
            setPage(pa);
          }
          if(data.code==20001&&data.msg=='请先登录'){
            $location.path('access.signin');
          }      
                  

          $scope.pageChanged = function(){           
            $http.post(
                $scope.app.backendurl+"tbl-equipment/view-all",
                {
                  'page': $scope.currentPage,  
                  'product_id':$state.params.pid,   
                  'token':$localStorage.token                  

                }
                ).success(function (data) {
                  if(data.code==0&&data.msg=='获取设备详细数据成功'){
                    $scope.aaData = data.data.list;
                  }
                  if(data.code==20001&&data.msg=='请先登录'){
                    $location.path('access.signin');
                  }      
                  
                  //console.log(data);

                 }).error(function (data) {
                    alert(data);
               })
          }
          
        
        }).error(function (data) {
            alert(data);
        })

   }

   $scope.getdevicelist($state.params.page); 

   function setPage (pageNo) {
      $scope.currentPage = pageNo || '1';
      $http.post(
        $scope.app.backendurl+"tbl-equipment/view-all",
        {
          'page': $scope.currentPage, 
          'product_id':$state.params.pid,     
          'token':$localStorage.token                  

        }
        ).success(function (data) {
          //console.log(data)
          if(data.code==0&&data.msg=='获取设备详细数据成功'){
            $scope.aaData = data.data.list;
          }
          if(data.code==20001&&data.msg=='请先登录'){
            $location.path('access.signin');
          }      
          
          //console.log(data);

         }).error(function (data) {
            alert(data);
       })
      
    
  }
    
})